package com.naiterui.ehp.bs.emr.utils;

import java.util.Date;
import java.util.List;

import org.springframework.util.Assert;

import com.naiterui.ehp.bp.constants.PatientIntelligentLabel;
import com.naiterui.common.redis.RedisUtil;

/**
 * <pre>
 *    患者智能标签
 * </pre>
 *
 * @author 王泽浩
 * @date 2018/7/30 下午2:27
 * @since 1.0.0
 */
public class PatientIntelligentLabelUtil {


    /**
     * 设置复诊时间
     *
     * @param doctorId  医生ID
     * @param patientId 患者id
     * @param date      复诊时间
     */
    public static void putRevisitTime(Long doctorId, Long patientId, Date date) {
        String revisitTimeKey = PatientIntelligentLabel.getRevisitTimeKey(doctorId);
        Assert.notNull(patientId, "设置复诊时间失败，患者ID不能为null");
        Assert.notNull(date, String.format("设置复诊时间失败，复诊时间不能为null，医生id:%s 患者id:%s", doctorId, patientId));
        RedisUtil.hashOps().hsetObject(revisitTimeKey, patientId + "", date);
    }

    /**
     * 删除复诊时间标签
     *
     * @param doctorId  医生ID
     * @param patientId 患者ID
     */
    public static void removeRevisitTime(Long doctorId, Long patientId) {
        String revisitTimeKey = PatientIntelligentLabel.getRevisitTimeKey(doctorId);
        RedisUtil.hashOps().hdelObject(revisitTimeKey, patientId + "");
    }

    /**
     * 设置诊断结果
     *
     * @param doctorId  医生ID
     * @param patientId 患者ID
     * @param diagnosis 诊断结果
     */
    public static void putDiagnosis(Long doctorId, Long patientId, List<String> diagnosis) {
        String diagnosisKey = PatientIntelligentLabel.getDiagnosisKey(doctorId);
        Assert.notNull(patientId, "设置复诊时间失败，患者ID不能为null");
        Assert.notNull(diagnosis, String.format("设置结果失败，复诊时间不能为null，医生id:%s 患者id:%s", doctorId, patientId));
        RedisUtil.hashOps().hsetObject(diagnosisKey, patientId + "", diagnosis);
    }

}
